'use strict';

import api from './config';
import axios from 'axios';

export const ossTlBookHost = "https://tl-book.oss-cn-beijing.aliyuncs.com/";
export const ossDailyEnglishHost = "https://everyday-en.oss-cn-beijing.aliyuncs.com/";
//获取oss签名
export function getOssSign(config) {
    return api.post('ali_oss/get_sign', {
        content_type: config.content_type,
        date: config.date,
        bucket: config.bucket,
        dir: config.dir,
        filename: config.filename,
        type: config.type,
        token:"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoxLCJleHAiOjE1MTUyMDQzNjUyNTksInJvbGVfaWQiOjB9.FSeUshr0s7FKFKsrHs8B4brdqE423fkKEpR-CAMZvLI"
    });
}

export function uploadToAliyun(config,formData,processFun){
    let url = "";
    switch (config.bucket) {
        case "tl-book":
            url = ossTlBookHost;
            break;
        case "everyday-en":
            url = ossDailyEnglishHost;
            break;
        default:
            break;
    }
    return axios({
        method: 'POST',
        url: url,
        data: formData,
        onUploadProgress: processFun
      });
}

